<?php

define('DB_PATH'            , dirname(__FILE__));
define('DB_ENV_PATH'        , DB_PATH . '/enviroment/');
define('DB_CONTROLLERS_PATH', DB_PATH . '/controllers/');
define('DB_CHANGESETS_PATH' , DB_PATH . '/changesets/');
define('DB_DATA_PATH'       , DB_PATH . '/data/');
define('DB_TABLES_PATH'     , DB_PATH . '/tables/');
define('DB_TEMPLATES_PATH'     , DB_PATH . '/templates/');

define('MAIN_APP_PATH' , dirname(DB_PATH));
require MAIN_APP_PATH . '/config.php';

$config = Nip_Config::instance();
if (!defined('DB_ADAPTER'))  define(DB_ADAPTER,  $config->DB->adapter);
if (!defined('DB_HOST'))     define(DB_HOST,     $config->DB->host);
if (!defined('DB_USER'))     define(DB_USER,     $config->DB->user);
if (!defined('DB_PASSWORD')) define(DB_PASSWORD, $config->DB->password);
if (!defined('DB_NAME'))     define(DB_NAME,     $config->DB->name);

/**
 * URLs
 */
$projectDir = implode('/', array_unique(array_intersect(explode('/', $_SERVER["REQUEST_URI"]), explode('/', str_replace('\\', '/', ROOT_PATH)))));
if ($projectDir[strlen($projectDir) - 1] != '/') {
    $projectDir .= '/';
}
define('PROJECT_DIR', $projectDir);

define('BASE_URL', 'http://' . $_SERVER['HTTP_HOST'] . PROJECT_DIR);

define('ASSETS_URL', BASE_URL . 'public/');
define('IMAGES_URL', ASSETS_URL . 'images/');
define('STYLES_URL', ASSETS_URL . 'css/');
define('SCRIPTS_URL', ASSETS_URL . 'js/');

session_start();
